#pragma once

#include "Point.h";

#include "Vector.h";

template<typename T2> class Flatness
{
	public:
		Flatness(Point<T2>& i_p1,Point<T2>& i_p2, Point<T2>& i_p3);
		double PointDeviation(const Point<T2>& i_p);
	public:	
		T2 m_a;
		T2 m_b;
		T2 m_c;
		T2 m_d;
};





template<typename T2> Flatness<T2>::Flatness(Point<T2>& i_p1, Point<T2>& i_p2, Point<T2>& i_p3)
{
	Vector<T2> first_vec(i_p1,i_p2);
	Vector<T2> second_vec(i_p1,i_p3);
	first_vec=first_vec^second_vec;
	m_a=first_vec.m_x;
	m_b=first_vec.m_y;
	m_c=first_vec.m_z;
	second_vec.m_x=i_p1.m_x;
	second_vec.m_y=i_p1.m_y;
	second_vec.m_z=i_p1.m_z;
	m_d=-1*(first_vec*second_vec);
};


template<typename T2> double Flatness<T2>::PointDeviation(const Point<T2>& i_p1)
{
	double div=double(1)/sqrt(m_a*m_a + m_b*m_b + m_c*m_c);
	double pre_val=m_a*i_p1.m_x + m_b*i_p1.m_y + m_c*i_p1.m_z + m_d;
	return pre_val*div;
};